home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1871 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: renaming file names from within C!
  5. Date: 17 Jan 1996 07:51:59 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4dirdf$t5s@umbc9.umbc.edu>
  8. References: <4dh7sb$6de@hammerhead.dadd.ti.com>
  9. NNTP-Posting-Host: f-umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Sudheer Vemulapalli  <sudheer@dadd.ti.com> wrote:
  13. |> I have a question. Please let me know how to do the following.
  14. |> 
  15. |> How can i move/rename a file in the UNIX system from within a C program.
  16. |> 
  17. |> Suppose i have two strings "a" and "b".
  18. |> 
  19. |> char *a, *b;
  20. |> 
  21. |> which contain the two strings. and let's say that a file exists with its
  22. |> name same as the string in "b". How can i rename it or mv it so that the
  23. |> file's name becomes same as string in "a".
  24. |> 
  25. |> Is there a short way of doing it rather than creating another file with new
  26. |> name and copying the contents of the old file into the new file and then
  27. |> removing the old file. 
  28.  
  29. This can be done completely n ANSI C using the rename function(). To do what
  30. you ask, assuming the variables 'a' and 'b' are valid strings, the call:
  31.  
  32. rename (b, a);
  33.  
  34. should make the filename corresponding to string 'b' correspond to string 'a'.
  35. -- 
  36. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  37.  
  38. Jonas J. Schlein  (schlein@gl.umbc.edu)
  39.